/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.sys.entity;

import javax.validation.Valid;

import com.jeesite.common.entity.BaseEntity;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.entity.TreeEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.common.utils.excel.annotation.ExcelField;
import com.jeesite.common.utils.excel.annotation.ExcelField.Align;
import com.jeesite.common.utils.excel.annotation.ExcelFields;
import com.jeesite.common.utils.excel.fieldtype.CompanyType;
import com.jeesite.common.utils.excel.fieldtype.OfficeType;

/**
 * 员工用户管理Entity
 * @author ThinkGem
 * @version 2017-03-25
 */
@Table(name="${_prefix}sys_user", alias="a", columns={
		@Column(includeEntity=User.class),
		@Column(name="accept",attrName="accept",label="是否同意条款",comment="是否同意条款"),
		@Column(name="identity", attrName="identity", label="用户身份", comment="身份标识(student,teacher)"),
		@Column(name="introduce",attrName="introduce",label="用户介绍",comment="用户介绍"),
		@Column(name="head_office",attrName="headOffice",label="总行标识",comment="总行标识"),
		@Column(name="branch_office",attrName="branchOffice",label="分行标识",comment="分行标识"),
		@Column(name="sub_branch",attrName="subBranch",label="支行标识",comment="支行标识"),
		@Column(name="small_local_branch",attrName="smallLocalBranch",label="分离处标识",comment="分离处标识"),
		@Column(name="input_offices",attrName="inputOffices",label="其他机构名称",comment="其他机构名称"),
		@Column(name="id_card",attrName="idCard",label="身份证号",comment="身份证号"),
		@Column(name="state",attrName="state",label="数据状态",comment="数据状态"),		
	}, joinTable={
		@JoinTable(type=Type.JOIN, entity=Employee.class, alias="e",
			on="e.emp_code=a.ref_code AND a.user_type=#{USER_TYPE_EMPLOYEE}",
			attrName="employee", columns={
				@Column(includeEntity=BaseEntity.class),
				@Column(includeEntity=DataEntity.class),
				@Column(name="emp_code", 	attrName="empCode", 			label="员工编码", isPK=true),
				@Column(name="emp_no", 		attrName="empNo", 				label="员工工号"),
				@Column(name="emp_name", 	attrName="empName", 			label="员工姓名", queryType=QueryType.LIKE),
				@Column(name="emp_name_en", attrName="empNameEn", 			label="英文名", queryType=QueryType.LIKE),
			}),
		@JoinTable(type=Type.LEFT_JOIN, entity=Office.class, alias="o", 
			on="o.office_code=e.office_code", attrName="employee.office",
			columns={
					@Column(includeEntity=DataEntity.class),
					@Column(includeEntity=TreeEntity.class),
					@Column(name="office_code", label="机构编码", isPK=true),
					@Column(name="parent_code", label="机构编码", isPK=true),
					@Column(name="parent_codes",label="所有父级编码", queryType=QueryType.LIKE),
					@Column(name="view_code", 	label="机构代码"),
					@Column(name="office_name", label="机构名称", isQuery=false),
					@Column(name="full_name", 	label="机构全称"),
					@Column(name="office_type", label="机构类型"),
					@Column(name="leader", 		label="负责人"),
					@Column(name="phone", 		label="电话"),
					@Column(name="address", 	label="联系地址"),
					@Column(name="zip_code", 	label="邮政编码"),
					@Column(name="email", 		label="邮箱"),
			}),
		@JoinTable(type=Type.LEFT_JOIN, entity=Company.class, alias="c", 
			on="c.company_code=e.company_code", attrName="employee.company",
			columns={
					@Column(includeEntity=DataEntity.class),
					@Column(includeEntity=TreeEntity.class),
					@Column(name="company_code", label="公司编码", isPK=true),
					@Column(name="parent_codes",label="所有父级编码", queryType=QueryType.LIKE),
					@Column(name="view_code", 	label="公司代码"),
					@Column(name="company_name", label="公司名称", isQuery=false),
					@Column(name="full_name", 	label="公司全称"),
					@Column(name="area_code", attrName="area.areaCode", label="区域编码"),
			}),
		@JoinTable(type=Type.LEFT_JOIN, entity=Area.class, alias="ar",
			on="ar.area_code = c.area_code", attrName="employee.company.area",
			columns={
					@Column(includeEntity=DataEntity.class),
					@Column(includeEntity=TreeEntity.class),
					@Column(name="area_code", label="区域代码", isPK=true),
					@Column(name="area_name", label="区域名称", isQuery=false),
					@Column(name="area_type", label="区域类型"),
		}),
	},
	extWhereKeys="dsfOffice, dsfCompany",
	orderBy="a.user_weight DESC, a.update_date DESC"
)
public class EmpUser extends User {
	
	private static final long serialVersionUID = 1L;
	private String identity;   //身份标识
	private Integer accept;//是否同意条款
	private String introduce;
	private String headOffice;
	private String branchOffice;
	private String subBranch;
	private String smallLocalBranch;
	private String[] codes; // 查询用
	private String employeePosts,idCard;
	private Integer state;
	private String firstOffice; //一级 
	private String secondOffice; //二级
    private String officeCode;//归属机构编码
    private String inputOffices;//输入的机构名成
    
	public String getInputOffices() {
		return inputOffices;
	}

	public void setInputOffices(String inputOffices) {
		this.inputOffices = inputOffices;
	}

	public String getOfficeCode() {
		return officeCode;
	}

	public void setOfficeCode(String officeCode) {
		this.officeCode = officeCode;
	}

	public EmpUser() {
		this(null);
	}

	public String getFirstOffice() {
		return firstOffice;
	}

	public void setFirstOffice(String firstOffice) {
		this.firstOffice = firstOffice;
	}

	public String getSecondOffice() {
		return secondOffice;
	}

	public void setSecondOffice(String secondOffice) {
		this.secondOffice = secondOffice;
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public String getEmployeePosts() {
		return employeePosts;
	}

	public void setEmployeePosts(String employeePosts) {
		this.employeePosts = employeePosts;
	}
	
	public String getIdCard() {
		return idCard;
	}

	public void setIdCard(String idCard) {
		this.idCard = idCard;
	}

	public EmpUser(String id){
		super(id);
	}
	
	@Valid
	@ExcelFields({
		@ExcelField(title="一级机构", attrName="firstOffice", align=Align.CENTER, sort=7,  type=ExcelField.Type.EXPORT),
		@ExcelField(title="二级机构", attrName="secondOffice", align=Align.CENTER, sort=8,  type=ExcelField.Type.EXPORT),
		@ExcelField(title="归属机构代码", attrName="officeCode", align=Align.CENTER, sort=9,type=ExcelField.Type.IMPORT),
		@ExcelField(title="归属机构", attrName="employee.office", align=Align.CENTER, sort=10, fieldType=OfficeType.class,type=ExcelField.Type.EXPORT),
		@ExcelField(title="用户名称", attrName="userName", align=Align.CENTER, sort=40),
		@ExcelField(title="电子邮箱", attrName="email", align=Align.LEFT, sort=50),
		@ExcelField(title="手机号码", attrName="mobile", align=Align.CENTER, sort=60),
		@ExcelField(title="办公电话", attrName="phone", align=Align.CENTER, sort=70),
		@ExcelField(title="性别", attrName="sex", dictType="sys_user_sex", width=10*256, align=Align.CENTER, sort=75),
		@ExcelField(title="岗位", attrName="employeePosts", align=Align.CENTER, sort=96),
		@ExcelField(title="身份证号", attrName="idCard", align=Align.CENTER, sort=97),
		@ExcelField(title="身份标识", attrName="identity", align=Align.CENTER, sort=100),
		@ExcelField(title="介绍", attrName="introduce", align=Align.CENTER, sort=101),
		@ExcelField(title="最后登录日期", attrName="lastLoginDate", width=20*256, align=Align.CENTER, sort=900, type=ExcelField.Type.EXPORT, dataFormat="yyyy-MM-dd HH:mm"),
	})
	public Employee getEmployee(){
		Employee employee = (Employee)super.getRefObj();
		if (employee == null){
			employee = new Employee(getRefCode());
			super.setRefObj(employee);
		}
		return employee;
	}
	
	public String getIdentity() {
		return identity;
	}

	public void setIdentity(String identity) {
		this.identity = identity;
	}

	public Integer getAccept() {
		return accept;
	}

	public void setAccept(Integer accept) {
		this.accept = accept;
	}
	
	public String getIntroduce() {
		return introduce;
	}

	public void setIntroduce(String introduce) {
		this.introduce = introduce;
	}

	public String getHeadOffice() {
		return headOffice;
	}

	public void setHeadOffice(String headOffice) {
		this.headOffice = headOffice;
	}

	public String getBranchOffice() {
		return branchOffice;
	}

	public void setBranchOffice(String branchOffice) {
		this.branchOffice = branchOffice;
	}

	public String getSubBranch() {
		return subBranch;
	}

	public void setSubBranch(String subBranch) {
		this.subBranch = subBranch;
	}

	public String getSmallLocalBranch() {
		return smallLocalBranch;
	}

	public void setSmallLocalBranch(String smallLocalBranch) {
		this.smallLocalBranch = smallLocalBranch;
	}

	public void setEmployee(Employee employee){
		super.setRefObj(employee);
	}

	public String[] getCodes() {
		return codes;
	}

	public void setCodes(String[] codes) {
		this.codes = codes;
	}
	
}